import fs from '@ohos.file.fs';
import window from '@ohos.window';
import db from '../common/core/db';
import utils from '../common/core/utils';
import logger from '../common/core/logger';
import current from '../common/core/current';
import globalData from '../common/core/globalData';
import UIAbility from '@ohos.app.ability.UIAbility';
import downloader from '../common/manager/downloader';
import serviceCache from '../common/manager/serviceCache';

export default class EntryAbility extends UIAbility {
  onCreate() {
    globalData.abilityContext = this.context;
    globalData.filesDir = this.context.filesDir;
    logger.init(this.context.filesDir);
    let root = `${this.context.filesDir}/${this.context.applicationInfo.name}`;
    fs.access(root, (err, res) => {
      if (!err && !res)
        fs.mkdir(root);
    });
  }

  onWindowStageCreate(windowStage: window.WindowStage) {
    utils.setLayoutFullScreen(windowStage, utils.COLOR_WHITE, utils.COLOR_BLACK, '#f7f7f7', utils.COLOR_BLACK);
    windowStage.loadContent('pages/Index');
    db.createInstance(this.context);
    current.instance.loadInfo();
    current.instance.loadSetting();
    serviceCache.createInstance(this.context);
    downloader.createInstance(this.context);
    utils.createRdbStore(this.context);
  }
}